function Territory(jsonObject) {
	this.internalObject = jsonObject;
}

Territory.prototype = {
	getRegionId: function() { return this.internalObject.RegionId; },
	setRegionId: function(regionid) { this.internalObject.RegionId = regionid; },
	getTerritoryDescription: function() { return this.internalObject.TerritoryDescription; },
	setTerritoryDescription: function(territorydescription) { this.internalObject.TerritoryDescription = territorydescription; },
	getTerritoryId: function() { return this.internalObject.TerritoryId; },
	getCreatedDate: function() { return this.internalObject.CreatedDate; },
	getCreatedBy: function() { return this.internalObject.CreatedBy; },
	getModifiedDate: function() { return this.internalObject.ModifiedDate; },
	getModifiedBy: function() { return this.internalObject.ModifiedBy; },
	getTerritoryObject: function() { return this.internalObject; }
};

function TerritoryService() {
}

TerritoryService.prototype.retrieveAll = function(successCallback) {
    viewServiceProxy.invokeGet("TerritoryList", successCallback, OnPageError, true);
};

TerritoryService.prototype.retrievePaged = function(successCallback, pageIndex, pageSize, sortOrder, sortColumn, linq) {
    var restUrl = "TerritoryListPage";
    restUrl = restUrl + "/?";

    if (!IsNullOrEmpty(pageIndex)) {
        restUrl = restUrl + "pageIndex=" + pageIndex;
        if (!IsNullOrEmpty(pageSize) || !IsNullOrEmpty(sortOrder) || !IsNullOrEmpty(sortColumn) || !IsNullOrEmpty(linq)) {
            restUrl = restUrl + "&";
        }
    }
    if (!IsNullOrEmpty(pageSize)) {
        restUrl = restUrl + "pageSize=" + pageSize;
        if (!IsNullOrEmpty(sortOrder) || !IsNullOrEmpty(sortColumn) || !IsNullOrEmpty(linq)) {
            restUrl = restUrl + "&";
        }
    }
    if (!IsNullOrEmpty(sortOrder)) {
        restUrl = restUrl + "sortOrder=" + sortOrder;
        if (!IsNullOrEmpty(sortColumn) || !IsNullOrEmpty(linq)) {
            restUrl = restUrl + "&";
        }
    }
    if (!IsNullOrEmpty(sortColumn)) {
        restUrl = restUrl + "sortColumn=" + sortColumn;
        if (!IsNullOrEmpty(linq)) {
            restUrl = restUrl + "&";
        }
    }
    restUrl = restUrl + "linq=" + linq;

    viewServiceProxy.invokeGet(restUrl, successCallback, OnPageError, true);
};

TerritoryService.prototype.save = function(territory, successCallback) {
viewServiceProxy.invokePut("Territory", territory.getTerritoryObject(), successCallback, OnPageError, true);
};
